<?php


namespace app\command;


use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;
use app\manage\model\UsersModel;
use app\manage\model\BankModel;

class Qkl extends Command
{
    protected function configure(){
        $this->setName('Qkl')->setDescription("Qkl auto exec");
    }

    protected function execute(Input $input, Output $output){
        //tetherTrader,tether: USDT;
        $items = $this->getFileData("D:\\wwwroot\\qkl\\nft\\ui\\trc20.txt");
        $ba = 100;
        $model = new BankModel();
        $count = 0;
        $start = 2;
        $tt = time();
        foreach ($items as $item){
            if ($count==0){
                $count++;
//                continue;
            }
//            $item = explode("\t",$item[0]);
//            $item = $item[1];
            $code = $item[0];
            $param = array(
              "bank_code"=>$code,
                "bank_type"=>"USDT(TRC20)",
                "bank_name"=>"USDT","add_time"=>time(),
                "pay_type"=>2,"uid"=>0
            );
//            $exist = $model->where("bank_code",$code)->find();
            $aa = "";
//            if (!$exist)
            {
//                $userid = $model->allowField(true)->insertGetId($param);
                $bb = "insert into ly_recaivables (address,type,pay_type,uid,add_time) values (";
//                $bb .= "'".$code."','USDT','USDT',2,0,".strval($tt).");";
                $bb .= "'".$code."','USDT(TRC20)',2,0,".strval($tt).");";
//                $bb .= "'".$code."','ETH','ETH',2,0,".strval($tt).");";
//                $bb .= "'".$code."','USDT(ERC20)','USDT',2,0,".strval($tt).");";
//                $bb .= "'".$code."','TRX','TRX',2,0,".strval($tt).");";
                echo $bb."\n";
            }
        }
        $b = 100;
    }


    public function getFileData($file)
    {
        if (!is_file($file)) {
            exit('没有文件');
        }

        $handle = fopen($file, 'r');
        if (!$handle) {
            exit('读取文件失败');
        }

        $items = array();
        while (($data = fgetcsv($handle)) !== false) {
            // 下面这行代码可以解决中文字符乱码问题
            // $data[0] = iconv('gbk', 'utf-8', $data[0]);

            // 跳过第一行标题
            if ($data[0] == 'name') {
                continue;
            }

            // data 为每行的数据，这里转换为一维数组
            $items[] = $data;
//            print_r($data);// Array ( [0] => tom [1] => 12 )

        }

        fclose($handle);
        return $items;
    }

}
